/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.ipccenter.orlov;

import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.transaction.UserTransaction;
import ru.ipccenter.orlov.exceptions.RollbackFailureException;

/**
 *
 * @author GigaIce
 */
@ManagedBean
@RequestScoped
public class Register {

    private String login;
    private String password;
    private String first_name;
    private String last_name;
    private String exc = "no";
    
    
    public Register()
    {}

    public String getLogin() {
        return login;
    }

    public String getPassword() {
        return password;
    }

    public String getFirst_name() {
        return first_name;
    }

    public String getLast_name() {
        return last_name;
    }
    
    public void setLogin(String login) {
        this.login = login;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setFirst_name(String first_name) {
        this.first_name = first_name;
    }

    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

    public String getExc() {
        return exc;
    }
    
    
    
    public void register()
    {
        Context context;
        UserTransaction utx = null;
        
        try
        {
            context = new javax.naming.InitialContext();
            utx = (UserTransaction) new InitialContext(null).lookup("java:comp/UserTransaction");
        }
        catch(Exception e)
        {
            System.err.println(e.getLocalizedMessage());
        }
                
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("AviaAgencyPU");
        
        EntityManager em = factory.createEntityManager();
        PlanesJpaController planesController = new PlanesJpaController(utx, factory);
        //login = planesController.findPlanes(2).getName();
        Planes plane = new Planes(null, "ccc", new Integer(100));
            exc = exc + "4";

        try
        {            
            exc = exc + "2";
            planesController.create(plane); 
            //usersController.edit(user);
            //usersController.destroy(2);
            //exc = exc + "3" + usersController.findUsers(1).getLastName();
        }
        catch( Exception e)
        {
            exc = exc + e.toString();
        }
    }
    
    public String go()
    {
        return login;
    }
}
